
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashMap;
import java.util.Queue;

public class Server extends Thread {
	private Queue<Message> receiveQueue;
	private int port;
	private int numOfNodes;
	private HashMap<Rule, Integer> receiveRule;
	private Queue<Message> delayReceiveQueue;
	private MessagePasser mp;

	public Server(Queue<Message> receiveQueue, int port, int numOfNodes,
			HashMap<Rule, Integer> receiveRule,
			Queue<Message> delayReceiveQueue, MessagePasser mp) {
		this.receiveQueue = receiveQueue;
		this.port = port;
		this.numOfNodes = numOfNodes;
		this.receiveRule = receiveRule;
		this.delayReceiveQueue = delayReceiveQueue;
		this.mp = mp;
	}

	public void run() {
		try {
			int n = 0;
			ServerSocket ss = new ServerSocket(port);
			while (true) {
				Socket s = ss.accept();
				new Receiver(s, receiveQueue, receiveRule, delayReceiveQueue,
						mp).start();
				n++;
				if (n == numOfNodes)
					break;
			}
			System.out.println("server out of loop");
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
